Passed
Push — develop ( 34ae61...ee5e63 )
by Paul
02:54
created

main.js ➔ jQuery   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A main.js ➔ ... ➔ ?!?.forEach.call 0 7 2
1
var pollux = {
2
	metabox: {},
3
};
4
5
pollux.metabox.hasValue = function( el ) {
6
	if( el.type === 'checkbox' ) {
7
		return el.checked === true;
8
	}
9
	return el.value !== '';
10
};
11
12
pollux.metabox.onChangeValue = function( el )
13
{
14
	pollux.metabox.setVisibility( el );
15
};
16
17
pollux.metabox.setVisibility = function( el )
18
{
19
	var dependency = document.getElementById( el.getAttribute( 'data-depends' ));
20
	el.closest( '.rwmb-field' ).style.display = pollux.metabox.hasValue( dependency ) ? '' : 'none';
21
	return dependency;
22
};
23
24
jQuery(function(x) {
0 ignored issues
show
Unused Code introduced by
The parameter x is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
25
26
	var depends = document.querySelectorAll( '.rwmb-input [data-depends]' );
27
28
	[].forEach.call( depends, function( el ) {
29
		var dependency = pollux.metabox.setVisibility( el );
30
		var event = dependency.type === 'checkbox' ? 'change' : 'keyup';
31
		dependency.addEventListener( event, function() {
32
			pollux.metabox.onChangeValue( el );
33
		}, false );
34
	});
35
36
});
37